04. How an App (like Pirate Fleet) Works

Downloading the Project

Now that you’ve had some time to think about this application’s design, it is time to start using it. Before you do anything else, you’ll need to first download the Pirate Fleet Xcode project (version 1).

When you are finished downloading the project, open it up using Xcode. The project contains many files, but for each exercise you'll only focus on a small portion of them — so don’t stress if you don’t know what every file or every line of code does yet.

How Does an App Work?

Now that we're back looking at an Xcode project, you may be wondering how it works compared to a Playground file. What really happens when I open a project and run the application?

The App Delegate

We know our code ends by running on a device, but we still don't know where our code starts in an Xcode project. Well… it is not simple to explain, but Xcode generates a starting point. Typically it does this by using the AppDelegate contained in the AppDelegate.swift file.

import UIKit

@UIApplicationMain

// MARK: - AppDelegate

class AppDelegate: UIResponder, UIApplicationDelegate {

  // MARK: Properties

  var window: UIWindow?

  // MARK: UIApplicationDelegate

  func application(application: UIApplication, didFinishLaunchingWithOptions
    launchOptions: [NSObject: AnyObject]?) -> Bool {
    return true
  }
}

If you try to start reading through this now, then it probably won't make much sense. That’s okay—you do not need to know the specifics at this time. All you need to know is that our application has a natural starting point, just like Playground files, and it is the AppDelegate.swift file.

So What About the Rest of the Code?

You may also be wondering, how does the AppDelegate incorporate the rest of our code? What about the ships and grids and other objects we identified for the Pirate Fleet app? They do not appear in the AppDelegate.

Well… they do get incorporated through something known as the App Life Cycle. We won't talk about the App Life Cycle right now, but rest assured we'll return to it in a later session. For now, each time you write some code, we'll let you know how the code you're writing will affect the overall app when it is run.